package com.bwie.goods.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.bwie.goods.config.AlipayConfig;
import com.bwie.goods.vo.GoodsVo;
import com.bwie.miaosha.common.utils.PageUtils;
import com.bwie.miaosha.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.goods.entity.GoodsEntity;
import com.bwie.goods.service.GoodsService;

import javax.xml.crypto.Data;


/**
 * 
 *
 * @author HouDing
 * @email 1398853436@qq.com
 * @date 2022-02-22 19:41:40
 */
@RestController
@RequestMapping("goods/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		GoodsEntity goods = goodsService.getById(id);

        return R.ok().put("goods", goods);
    }
    //秒杀列表
    @RequestMapping("/miaoshalist")
    public R miaoshaList() {
        List<GoodsVo> goodsVos = goodsService.findGoods();
        return R.ok().put("goodsVos",goodsVos);
    }
    //详情页
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id){
        GoodsVo goodsVos = goodsService.findGoodVoById(id);
        Date now = new Date();
        goodsVos.setNow(now);
        return R.ok().put("goodsVos", goodsVos);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody GoodsEntity goods){
		goodsService.save(goods);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody GoodsEntity goods){
		goodsService.updateById(goods);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		goodsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
